package com.tuni.birthdaymoney.service.spring;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.tuni.birthdaymoney.persistence.entity.NotificationSettings;
import com.tuni.birthdaymoney.persistence.repository.NotificationSettingsRepository;
import com.tuni.birthdaymoney.service.SettingsService;

@Service
public class SpringSettingsService implements SettingsService {

    @Autowired
    private NotificationSettingsRepository notificationSettingsRepository;

    private NotificationSettings getFirst(Iterable<NotificationSettings> settingsList) {
        for (NotificationSettings settingsItem : settingsList) {
            return settingsItem;
        }
        return null;
    }
    
    @Override
    public NotificationSettings loadNotificationSettings() {
        return getFirst(notificationSettingsRepository.findAll());
    }

    @Override
    public void saveNotificationSettings(NotificationSettings settings) {
        notificationSettingsRepository.save(settings);
    }
}
